package com.hundsun.fcp.activity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.GetChars;
import android.widget.Toast;

import com.hundsun.fcp.R;
import com.hundsun.fcp.base.BaseActivity;
import com.hundsun.fcp.base.BaseProtectActivity;
import com.hundsun.fcp.fragments.AssetsFragments;
import com.hundsun.fcp.fragments.IndexFragments;
import com.hundsun.fcp.fragments.MineFragments;
import com.hundsun.fcp.impl.IFooterMenuHiddenListener;
import com.hundsun.fcp.impl.OnFooterMenuItemListener;
import com.hundsun.fcp.receivers.SystemLotteryReceivers;
import com.hundsun.fcp.widget.FooterMenu;

public class MainActivity extends BaseProtectActivity implements IFooterMenuHiddenListener{
	private SystemLotteryReceivers lotteryReceivers ; 
	private FooterMenu mFooterMenu ;

	private long exitTime;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		lotteryReceivers = new SystemLotteryReceivers() ;
		IntentFilter filter = new IntentFilter() ;
		filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) ;
		filter.addAction(Intent.ACTION_SCREEN_OFF) ;
		filter.addAction(Intent.ACTION_SCREEN_ON) ;
		registerReceiver(lotteryReceivers, filter ) ;
		setContentView(R.layout.activity_main) ;
		initFooter() ;
	}
	
	@Override
	protected void onDestroy() {
		unregisterReceiver(lotteryReceivers) ;
		super.onDestroy();
	}
	
	private void initFooter() {
		mFooterMenu = new FooterMenu(this);
		getFooterMenu().setOnFooterMenuItemListener(new OnFooterMenuItemListener() {
			
			@Override
			public void onItemClick(int index) {
				//switchContent(index) ;
			}
		}) ;
		getFooterMenu().switchHome() ;
	}
	
	
	
	@Override
	public void onBackPressed() {
		
		if(!getFooterMenu().back()){
			if((System.currentTimeMillis()-exitTime) > 2000){
				Toast.makeText(getApplicationContext(), getResources().getString(R.string.out_later), Toast.LENGTH_SHORT).show();                                
				exitTime = System.currentTimeMillis();   
			} else {
				setNeedLock(true) ;
				quitApplication() ;
				super.onBackPressed();
			}
		}
		
	}

	@Override
	public void visiable() {
		getFooterMenu().show(true) ;
	}

	@Override
	public void gone() {
		getFooterMenu().show(false) ;
	}

	public FooterMenu getFooterMenu() {
		return mFooterMenu;
	}

}
